package com.jstyle.jclife.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.jstyle.jclife.R;
import com.jstyle.jclife.model.StepData;

import java.text.NumberFormat;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/7/12.
 */

public class HistoryStepYearAdapter extends RecyclerViewBaseAdapter {

    NumberFormat format;

    public HistoryStepYearAdapter(List<StepData> stepDataList) {
        super(stepDataList);
        format = NumberFormat.getNumberInstance();
        format.setMaximumFractionDigits(1);
        format.setGroupingUsed(false);
    }

    @Override
    protected void bindData(BaseViewHolder holder, int position) {
        HistoryStepYearViewHolder historyStepWeekViewHolder = (HistoryStepYearViewHolder) holder;
        StepData stepData = (StepData) mDataList.get(position);

        historyStepWeekViewHolder.buttonHistoryYear.setText(stepData.getDate());
        float data = Float.valueOf(stepData.getStep());
        String showData = "";
        showData = format.format(data) + stepData.getShowLabel();
        historyStepWeekViewHolder.buttonHistoryYearData.setText(showData);
    }

    @Override
    protected int getLayoutId(int viewType) {
        return R.layout.item_history_year;
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(getLayoutId(viewType), parent, false);
        BaseViewHolder baseViewHolder = new HistoryStepYearViewHolder(view);
        return baseViewHolder;
    }

    class HistoryStepYearViewHolder extends BaseViewHolder {
        @BindView(R.id.button_history_year)
        Button buttonHistoryYear;
        @BindView(R.id.button_history_year_data)
        Button buttonHistoryYearData;

        public HistoryStepYearViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
